import unittest
import requests
import sys
import os

# 加入项目根路径
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from api import log
from tools import parser_html
from api.api_register_login import ApiRegisterLogin
from api.api_tender import ApiTender
from api.api_approve_trust import ApiApproveTrust

class TestTenderList(unittest.TestCase):
    def setUp(self) -> None:
        self.session = requests.session()
        self.reg = ApiRegisterLogin(self.session)
        self.approve = ApiApproveTrust(self.session)
        self.tender = ApiTender(self.session)

    def tearDown(self) -> None:
        self.session.close()

    def test01_tender_list(self):
        phone  = "13633331311"
        verifycode = 8888
        pwd = "test123"
        phone_code = 666666
        card_id = "654226195310194894"

        # 1.获取图片验证码
        self.reg.api_img_code(123123)

        # 2.获取短信验证码
        self.reg.api_phone_code(phone,  verifycode)

        # 3.注册
        self.reg.api_register(phone, pwd,  verifycode, phone_code)

        # 4.登录
        self.reg.api_login(phone, pwd)

        # 5.认证
        self.approve.api_approve("李四",card_id)

        # 6.后台开户
        
        r = self.approve.api_trust()

        # 7.三方开户
        # result = parser_html(r)
        # r = self.session.post(url=result[0], data=result[1]) 
        # print("三方开户接口结果：", r.text)
        # self.assertIn("OK", r.text)
        # log.info("开户执行结果为：{}".format(r.text))

        # # 8.获取充值验证码
        # self.approve.api_img_code(123123)

        # # 9.后台充值
        # r = self.approve.api_recharge(verifycode)

        # # 10.三方充值
        # result = parser_html(r)
        # r = self.session.post(url=result[0], data=result[1]) 
        # print("三方充值接口结果：", r.text)
        # self.assertIn("OK", r.text)
        # log.info("充值执行结果为：{}".format(r.text))

        # # 11.后台投资
        # r = self.tender.api_tender(100)  

        # # 12.三方投资
        # result = parser_html(r)
        # r = self.session.post(url=result[0], data=result[1]) 
        # print("三方投资接口结果：", r.text)
        # self.assertIn("OK", r.text)
        # log.info("投资执行结果为：{}".format(r.text))

if __name__ == '__main__':
    unittest.main()
